﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Max.PH5_2103A.Shopping.TEntityFrame.IService
{
    /// <summary>
    /// 基于DTO的CRUD基本的服务接口
    /// </summary>
    public interface IBaseServiceByDto<TEntity,TInputDto,TOutputDto> where TEntity : class
    {
        #region Insert -- 添加
        /// <summary>
        /// 添加一条数据
        /// </summary>
        /// <param name="t"></param>
        /// <returns>返回受影响行数</returns>
        int Insert(TInputDto t);

        /// <summary>
        /// 批量添加数据
        /// </summary>
        /// <param name="list"></param>
        /// <returns>返回受影响行数</returns>
        int Insert(List<TInputDto> list);

        #endregion

        #region Update -- 修改
        /// <summary>
        /// 修改一条数据
        /// </summary>
        /// <param name="t"></param>
        /// <returns>返回受影响行数</returns>
        int Update(TInputDto t);

        /// <summary>
        /// 批量修改数据
        /// </summary>
        /// <param name="list"></param>
        /// <returns>返回受影响行数</returns>
        int Update(List<TInputDto> list);
        #endregion

        #region Delete -- 删除
        /// <summary>
        /// 根据实体删除一条数据
        /// </summary>
        /// <param name="t"></param>
        /// <returns>返回受影响行数</returns>
        int Delete(TInputDto t);

        /// <summary>
        /// 根据实体批量删除数据
        /// </summary>
        /// <param name="list"></param>
        /// <returns>返回受影响行数</returns>
        int Delete(List<TInputDto> list);

        /// <summary>
        /// 根据ID删除一条数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns>返回受影响行数</returns>
        int Delete(object id);

        /// <summary>
        /// 根据ID批量删除数据
        /// </summary>
        /// <param name="ids"></param>
        /// <returns>返回受影响行数</returns>
        int Delete(List<object> ids);
        #endregion

        #region Select -- 查询
        /// <summary>
        /// 查询所有数据
        /// </summary>
        /// <returns></returns>
        IQueryable<TOutputDto> SelectAll();

        /// <summary>
        /// 根据ID查询一条数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        TOutputDto SelectFirstById(object id);

        /// <summary>
        /// 查询分页数据
        /// </summary>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="total">总条数</param>
        /// <returns></returns>
        IQueryable<TOutputDto> SelectAll(int pageIndex, int pageSize, out int total);

        /// <summary>
        /// 根据条件分页查询
        /// </summary>
        /// <param name="where">查询条件的表达式</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="total">总条数</param>
        /// <returns></returns>
        IQueryable<TOutputDto> SelectAll(System.Linq.Expressions.Expression<Func<TEntity, bool>> where, int pageIndex, int pageSize, out int total);

        /// <summary>
        /// 根据条件分页查询并排序
        /// </summary>
        /// <typeparam name="TKey"></typeparam>
        /// <param name="where">查询表达式</param>
        /// <param name="sort">排序表达式</param>
        /// <param name="isAsc">是升序还是降序</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="total">总条数</param>
        /// <returns></returns>
        IQueryable<TOutputDto> SelectAll<TKey>(System.Linq.Expressions.Expression<Func<TEntity, bool>> where, Func<TEntity, TKey> sort, bool isAsc, int pageIndex, int pageSize, out int total);
        #endregion
    }
}
